package com.ddone.demo.mapper;

import com.ddone.demo.bean.Emp;
import com.ddone.demo.utils.MybatisUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

/**
 * @author ddone
 * @date 2024/3/19-00:03
 */
public class testQueryPage {
    private SqlSession sqlSession;
    private EmpAnnotation mapper;

    @Before
    public void init() {
        sqlSession = MybatisUtil.openAutoSession();
        mapper = sqlSession.getMapper(EmpAnnotation.class);
    }

    @Test
    public void testPage() {
        List<Emp> empList = mapper.selectAll();
        System.out.println(empList);
        PageHelper.startPage(1,1);
        PageInfo<Emp> pageInfo = new PageInfo<>(empList);
        //当前页的数据
        List<Emp> list = pageInfo.getList();
        System.out.println("list = " + list);
        //返回的总条数
        long total = pageInfo.getTotal();
        System.out.println("total = " + total);
        //返回的总页数
        //总页数
        int pages = pageInfo.getPages();
        System.out.println("pages = " + pages);
    }

    @After
    public void destroy() {
        sqlSession.close();
    }
}
